/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package warmachinesystem.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;

import warmachinesystem.ArmyList;
import warmachinesystem.BaseUnit;
import warmachinesystem.SpecialRule;
import warmachinesystem.UnitKind;
import warmachinesystem.WarmachineSystemPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Base Unit</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link warmachinesystem.impl.BaseUnitImpl#getCode <em>Code</em>}</li>
 *   <li>{@link warmachinesystem.impl.BaseUnitImpl#getArmyList <em>Army List</em>}</li>
 *   <li>{@link warmachinesystem.impl.BaseUnitImpl#getPointCost <em>Point Cost</em>}</li>
 *   <li>{@link warmachinesystem.impl.BaseUnitImpl#getName <em>Name</em>}</li>
 *   <li>{@link warmachinesystem.impl.BaseUnitImpl#getUnitRules <em>Unit Rules</em>}</li>
 *   <li>{@link warmachinesystem.impl.BaseUnitImpl#getFieldAllowance <em>Field Allowance</em>}</li>
 *   <li>{@link warmachinesystem.impl.BaseUnitImpl#getTag <em>Tag</em>}</li>
 *   <li>{@link warmachinesystem.impl.BaseUnitImpl#getKind <em>Kind</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class BaseUnitImpl extends EObjectImpl implements BaseUnit {
	/**
	 * The default value of the '{@link #getCode() <em>Code</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCode()
	 * @generated
	 * @ordered
	 */
	protected static final String CODE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getCode() <em>Code</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCode()
	 * @generated
	 * @ordered
	 */
	protected String code = CODE_EDEFAULT;

	/**
	 * The default value of the '{@link #getPointCost() <em>Point Cost</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPointCost()
	 * @generated
	 * @ordered
	 */
	protected static final int POINT_COST_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getPointCost() <em>Point Cost</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPointCost()
	 * @generated
	 * @ordered
	 */
	protected int pointCost = POINT_COST_EDEFAULT;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getUnitRules() <em>Unit Rules</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUnitRules()
	 * @generated
	 * @ordered
	 */
	protected EList<SpecialRule> unitRules;

	/**
	 * The default value of the '{@link #getFieldAllowance() <em>Field Allowance</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFieldAllowance()
	 * @generated
	 * @ordered
	 */
	protected static final String FIELD_ALLOWANCE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getFieldAllowance() <em>Field Allowance</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFieldAllowance()
	 * @generated
	 * @ordered
	 */
	protected String fieldAllowance = FIELD_ALLOWANCE_EDEFAULT;

	/**
	 * The default value of the '{@link #getTag() <em>Tag</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTag()
	 * @generated
	 * @ordered
	 */
	protected static final String TAG_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getTag() <em>Tag</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTag()
	 * @generated
	 * @ordered
	 */
	protected String tag = TAG_EDEFAULT;

	/**
	 * The default value of the '{@link #getKind() <em>Kind</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getKind()
	 * @generated
	 * @ordered
	 */
	protected static final UnitKind KIND_EDEFAULT = UnitKind.UNIT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected BaseUnitImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return WarmachineSystemPackage.Literals.BASE_UNIT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ArmyList getArmyList() {
		if (eContainerFeatureID() != WarmachineSystemPackage.BASE_UNIT__ARMY_LIST) return null;
		return (ArmyList)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetArmyList(ArmyList newArmyList, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newArmyList, WarmachineSystemPackage.BASE_UNIT__ARMY_LIST, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setArmyList(ArmyList newArmyList) {
		if (newArmyList != eInternalContainer() || (eContainerFeatureID() != WarmachineSystemPackage.BASE_UNIT__ARMY_LIST && newArmyList != null)) {
			if (EcoreUtil.isAncestor(this, newArmyList))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newArmyList != null)
				msgs = ((InternalEObject)newArmyList).eInverseAdd(this, WarmachineSystemPackage.ARMY_LIST__BASE_UNITS, ArmyList.class, msgs);
			msgs = basicSetArmyList(newArmyList, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WarmachineSystemPackage.BASE_UNIT__ARMY_LIST, newArmyList, newArmyList));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getPointCost() {
		return pointCost;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPointCost(int newPointCost) {
		int oldPointCost = pointCost;
		pointCost = newPointCost;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WarmachineSystemPackage.BASE_UNIT__POINT_COST, oldPointCost, pointCost));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WarmachineSystemPackage.BASE_UNIT__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<SpecialRule> getUnitRules() {
		if (unitRules == null) {
			unitRules = new EObjectResolvingEList<SpecialRule>(SpecialRule.class, this, WarmachineSystemPackage.BASE_UNIT__UNIT_RULES);
		}
		return unitRules;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getFieldAllowance() {
		return fieldAllowance;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setFieldAllowance(String newFieldAllowance) {
		String oldFieldAllowance = fieldAllowance;
		fieldAllowance = newFieldAllowance;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WarmachineSystemPackage.BASE_UNIT__FIELD_ALLOWANCE, oldFieldAllowance, fieldAllowance));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getTag() {
		return tag;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTag(String newTag) {
		String oldTag = tag;
		tag = newTag;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WarmachineSystemPackage.BASE_UNIT__TAG, oldTag, tag));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public UnitKind getKind() {
		// TODO: implement this method to return the 'Kind' attribute
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getCode() {
		return code;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCode(String newCode) {
		String oldCode = code;
		code = newCode;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WarmachineSystemPackage.BASE_UNIT__CODE, oldCode, code));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case WarmachineSystemPackage.BASE_UNIT__ARMY_LIST:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetArmyList((ArmyList)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case WarmachineSystemPackage.BASE_UNIT__ARMY_LIST:
				return basicSetArmyList(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case WarmachineSystemPackage.BASE_UNIT__ARMY_LIST:
				return eInternalContainer().eInverseRemove(this, WarmachineSystemPackage.ARMY_LIST__BASE_UNITS, ArmyList.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case WarmachineSystemPackage.BASE_UNIT__CODE:
				return getCode();
			case WarmachineSystemPackage.BASE_UNIT__ARMY_LIST:
				return getArmyList();
			case WarmachineSystemPackage.BASE_UNIT__POINT_COST:
				return getPointCost();
			case WarmachineSystemPackage.BASE_UNIT__NAME:
				return getName();
			case WarmachineSystemPackage.BASE_UNIT__UNIT_RULES:
				return getUnitRules();
			case WarmachineSystemPackage.BASE_UNIT__FIELD_ALLOWANCE:
				return getFieldAllowance();
			case WarmachineSystemPackage.BASE_UNIT__TAG:
				return getTag();
			case WarmachineSystemPackage.BASE_UNIT__KIND:
				return getKind();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case WarmachineSystemPackage.BASE_UNIT__CODE:
				setCode((String)newValue);
				return;
			case WarmachineSystemPackage.BASE_UNIT__ARMY_LIST:
				setArmyList((ArmyList)newValue);
				return;
			case WarmachineSystemPackage.BASE_UNIT__POINT_COST:
				setPointCost((Integer)newValue);
				return;
			case WarmachineSystemPackage.BASE_UNIT__NAME:
				setName((String)newValue);
				return;
			case WarmachineSystemPackage.BASE_UNIT__UNIT_RULES:
				getUnitRules().clear();
				getUnitRules().addAll((Collection<? extends SpecialRule>)newValue);
				return;
			case WarmachineSystemPackage.BASE_UNIT__FIELD_ALLOWANCE:
				setFieldAllowance((String)newValue);
				return;
			case WarmachineSystemPackage.BASE_UNIT__TAG:
				setTag((String)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case WarmachineSystemPackage.BASE_UNIT__CODE:
				setCode(CODE_EDEFAULT);
				return;
			case WarmachineSystemPackage.BASE_UNIT__ARMY_LIST:
				setArmyList((ArmyList)null);
				return;
			case WarmachineSystemPackage.BASE_UNIT__POINT_COST:
				setPointCost(POINT_COST_EDEFAULT);
				return;
			case WarmachineSystemPackage.BASE_UNIT__NAME:
				setName(NAME_EDEFAULT);
				return;
			case WarmachineSystemPackage.BASE_UNIT__UNIT_RULES:
				getUnitRules().clear();
				return;
			case WarmachineSystemPackage.BASE_UNIT__FIELD_ALLOWANCE:
				setFieldAllowance(FIELD_ALLOWANCE_EDEFAULT);
				return;
			case WarmachineSystemPackage.BASE_UNIT__TAG:
				setTag(TAG_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case WarmachineSystemPackage.BASE_UNIT__CODE:
				return CODE_EDEFAULT == null ? code != null : !CODE_EDEFAULT.equals(code);
			case WarmachineSystemPackage.BASE_UNIT__ARMY_LIST:
				return getArmyList() != null;
			case WarmachineSystemPackage.BASE_UNIT__POINT_COST:
				return pointCost != POINT_COST_EDEFAULT;
			case WarmachineSystemPackage.BASE_UNIT__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case WarmachineSystemPackage.BASE_UNIT__UNIT_RULES:
				return unitRules != null && !unitRules.isEmpty();
			case WarmachineSystemPackage.BASE_UNIT__FIELD_ALLOWANCE:
				return FIELD_ALLOWANCE_EDEFAULT == null ? fieldAllowance != null : !FIELD_ALLOWANCE_EDEFAULT.equals(fieldAllowance);
			case WarmachineSystemPackage.BASE_UNIT__TAG:
				return TAG_EDEFAULT == null ? tag != null : !TAG_EDEFAULT.equals(tag);
			case WarmachineSystemPackage.BASE_UNIT__KIND:
				return getKind() != KIND_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (code: ");
		result.append(code);
		result.append(", pointCost: ");
		result.append(pointCost);
		result.append(", name: ");
		result.append(name);
		result.append(", fieldAllowance: ");
		result.append(fieldAllowance);
		result.append(", tag: ");
		result.append(tag);
		result.append(')');
		return result.toString();
	}

} //BaseUnitImpl
